
* working directory
cd "ENTER PATH HERE"

* load dataset
use "replication_data.dta", clear

******************************************************************************************
**** Figure 1: Descrptive analysis
cibar tone, over(gov backsliding e_country) vce(cluster name) graphopts(ytitle("Tone")note("Note:  95% CIs Shown", span size(vsmall)) legend(pos(6) ring(1) col(1) size(small)))

* Figure 2
graph export "descriptive_graph.pdf"

******************************************************************************************


* Run ttests
eststo clear
bysort country par_spell: eststo: ttest tone, by(gov) unequal

* Table D2
eststo clear
quietly estpost ttest tone if country == "Malawi" & par_spell == 3, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Malawi" & par_spell == 4, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Malawi" & par_spell == 5, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Malawi" & par_spell == 6, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Zambia" & par_spell == 1, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Zambia" & par_spell == 2, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Zambia" & par_spell == 3, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")
quietly estpost ttest tone if country == "Zambia" & par_spell == 4, by(gov) unequal
esttab, noobs cells("b(star fmt(4)) se(fmt(4)) count(fmt(0))") star(* 0.05 ** 0.01) collabels ("Diff." "Std. Error" "Obs.")


* descriptive statistics for all variables
* Table D1
sum tone sentiment gov backsliding minister newcomer indep female if government == 1


******************************************************************************************************
*** Hypothesis 1
eststo clear
eststo: ologit tone i.gov i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

*** simulations
margins gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) xtitle("Tone") ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive")) name("predict", replace) title("") 

* Figure 3
graph export "h1_sims.pdf"


***************************************************************************************************************
*** Hypotheses 2-3
eststo: ologit tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country  if government == 1, cluster(name)

*** simulations
margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of backsliding on" "government and opposition tone") name("effect1", replace) 

margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of" "government membership on tone") name("effect2", replace) 

gr combine effect2 effect1, iscale(0.6) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))


* Figure 4
graph export "main_effects.pdf"

* Table D3
esttab using "main_results.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)




***************************************************************************************************************
*** Do MPs speak more about democracy during backsliding?
eststo clear
eststo: ologit democracy i.gov##i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

*** simulations
margins gov#backsliding

margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(3 "Other" 4 "Democracy")) title("Marginal effect of backsliding" "on speeches related to democracy") name("effect1", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(3 "Other" 4 "Democracy")) title("Marginal effect of government membership" "on speeches related to democracy") name("effect2", replace) 



*** Difference in tone on democracy speeches?
eststo: ologit tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country if government == 1 & democracy == 1, cluster(name)

*** simulations
margins gov#backsliding

margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of backsliding on" "government and opposition tone" "for democracy speeches") name("effect3", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of" "government membership on tone" "for democracy speeches") name("effect4", replace) 


gr combine effect2 effect1 effect4 effect3,  rows(2) iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))

* Figure 6
graph export "dem_speeches.pdf"

* Table D8
esttab using "democracy_model.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)



*******************************************************************************************
*** Differentiate effects for government and opposition based on support for the president
eststo clear
eststo: ologit tone i.gov##i.backsliding##c.pres_share minister newcomer indep female parliament year i.e_country if government ==1, cluster(name)

margins backsliding, at(pres_share = (0(0.1)1) gov = 0)
marginsplot, horizontal unique recast(scatter) graphregion(color(white)) bgcolor(white) ytitle("President Share") aspectratio(1) legend(order(7 "Stability, Negative" 8 "Stability, Neutral" 9 "Stability, Positive" 10 "Backsliding, Negative" 11 "Backsliding, Neutral" 12 "Backsliding, Positive")) name("margins", replace) title("Predictive margins of backsliding" "over pres. support for opposition MPs") 


margins r.backsliding, at(pres_share = (0(0.1)1) gov = 0)
marginsplot, horizontal unique xline(0, lcolor(cranberry))  recast(scatter) graphregion(color(white)) bgcolor(white) ytitle("President Share") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive")) name("effect1", replace) title("Marginal effect of backsliding" "over pres. support for opposition MPs") 

gr combine margins effect1, iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))

* Figure 5
graph export "support_effect.pdf"

* Table D7
esttab using "pres_support.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)




***************************************************************************************************************
***************************************************************************************************************
*** dictionary sentiment
* Hypothesis 1

eststo clear
eststo: reg sentiment i.gov i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

* simulations
margins gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) xtitle("Sentiment") ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive")) name("predict", replace) title("") 

* Figure D1
graph export "h1_dictionary.pdf"

* Hypotheses 2-3
eststo: reg sentiment i.gov##i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

* simulations
margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of backsliding on" "government and opposition sentiment") name("effect1", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of" "government membership on sentiment") name("effect2", replace) 

gr combine effect2 effect1, iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))

* Figure D2
graph export "main_effects_dictionary.pdf"

* Table D4
esttab using "dictionary.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)



******************************************************************************************
******************************************************************************************
*** MP fixed effects
* Hypothesis 1
eststo clear
eststo: ologit tone i.gov i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

*** simulations
margins gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) xtitle("Tone") ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive")) name("predict", replace) title("") 

* Figure D3
graph export "mp_fe_h1.pdf"


*** Hypotheses 2-3
eststo: ologit tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country i.e_name  if government == 1, cluster(name)

*** simulations
margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of backsliding on" "government and opposition tone") name("effect1", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) legend(order(4 "Negative" 5 "Neutral" 6 "Positive"))  title("Marginal effect of" "government membership on tone") name("effect2", replace) 

gr combine effect2 effect1, iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))

* Figure D4
graph export "mp_fe_results.pdf"

* Table D5
esttab using "mp_fe_results.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)








******************************************************************************************
******************************************************************************************
*** drop newcomers during backsliding

drop if newcomer == 1 & country == "Zambia" & par_spell == 4
drop if newcomer == 1 & country == "Malawi" & parliament == 2009

*** Hypothesis 1
eststo clear
eststo: ologit tone i.gov i.backsliding minister newcomer indep female parliament year i.e_country if government == 1, cluster(name)

*** Hypotheses 2-3
eststo: ologit tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country  if government == 1, cluster(name)

* Table D9
esttab using "no_newcomers.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2) replace



***************************************************************************************************************
***************************************************************************************************************
*** What about cohesion of opposition parties?

* load dataset
use "replication_data.dta", clear

gen mcp = 0
replace mcp = 1 if party == "MCP"
gen udf = 0
replace udf = 1 if party == "UDF"
gen upnd = 0
replace upnd = 1 if party == "UPND"


keep if backsliding == 1
collapse (first) country (mean) tone (sd) sd_tone=tone, by(name party)


keep if party == "DPP" | party == "MCP" | party == "UDF" | party == "PF" | party == "UPND" 


graph box tone, over(party, label(angle(45))) ///
    by(country, title("Distribution of Tone by Party") note("") ///
    graphregion(color(white)) bgcolor(white)) ///
    ytitle("Tone") ///
    box(1, lcolor(black)) box(2, lcolor(black)) ///
    medtype(line) medline(lwidth(medium)) ///
    name(box_by_party_country, replace)

graph box tone if country == "Malawi", over(party, label(angle(45))) ///
    ytitle("Tone") ///
    title("Malawi") ///
    graphregion(color(white)) bgcolor(white) ///
    name(malawi_box, replace)
	
graph box tone if country == "Zambia", over(party, label(angle(45))) ///
    ytitle("Tone") ///
    title("Zambia") ///
    graphregion(color(white)) bgcolor(white) ///
    name(zambia_box, replace)
	
graph combine malawi_box zambia_box, ///
    title("") ///
    graphregion(color(white)) iscale(1) ///
    name(tone_box_by_country, replace)	

* Figure 7
graph export "cohesion.pdf"



***************************************************************************************************************
***************************************************************************************************************
*** Trend graph


* load dataset
use "replication_data.dta", clear


gen speeches = 1

collapse (first) year parliament par_spell name constituency party female newcomer minister future_gov indep backsliding democracy (sum) localism tone speeches, by(country date gov)

gen av_tone = tone/speeches


replace date = date - 21916 if country == "Malawi" & year < 2015
replace date = date - 43830 - 3652 if country == "Malawi" & year > 2014 | country == "Zambia"
drop if date < 0
format date %td


*** Malawi (18070-19054)
twoway ///
(lpoly tone date if gov == 0 & country == "Malawi" & par_spell == 3, lcolor("50 50 50") lpattern(dot)) ///
(lpoly tone date if gov == 1 & country == "Malawi" & par_spell == 3, lcolor("50 50 50") lpattern(shortdash)) ///
(lpoly tone date if gov == 0 & country == "Malawi" & par_spell == 4, lcolor("50 50 50") lpattern(solid)) ///
(lpoly tone date if gov == 1 & country == "Malawi" & par_spell == 4, lcolor("50 50 50") lpattern(dash)) ///
(lpoly tone date if gov == 0 & country == "Malawi" & par_spell > 4, lcolor("50 50 50") lpattern(dot)) ///
(lpoly tone date if gov == 1 & country == "Malawi" & par_spell > 4, lcolor("50 50 50") lpattern(shortdash)), ///
graphregion(color(white)) bgcolor(white) ///
ytitle("Tone") xtitle("") ///
legend(off) ///
title("MP Tone in the Malawian Parliament") ///
tlabel(18070 19054, format(%tdnn/DD/YY) labsize(medium) angle(45)) ///
name(malawi_events, replace)


*** Zambia(20146-22262)
twoway ///
(lpoly tone date if gov == 0 & country == "Zambia" & par_spell < 4, lcolor("50 50 50") lpattern(dot)) ///
(lpoly tone date if gov == 1 & country == "Zambia" & par_spell < 4, lcolor("50 50 50") lpattern(shortdash)) ///
(lpoly tone date if gov == 0 & country == "Zambia" & par_spell == 4, lcolor("50 50 50") lpattern(solid)) ///
(lpoly tone date if gov == 1 & country == "Zambia" & par_spell == 4, lcolor("50 50 50") lpattern(dash)), ///
graphregion(color(white)) bgcolor(white) ///
ytitle("Tone") xtitle("Date") ///
legend(position(6) cols(4) order(1 2 3 4) fcolor(white) ///
    label(2 "Government, stability") ///
    label(1 "Opposition, stability") ///
    label(4 "Government, backsliding") ///
    label(3 "Opposition, backsliding")) ///
title("MP Tone in the Zambian Parliament") ///
tlabel(20146 22262, format(%tdnn/DD/YY) labsize(medium) angle(45)) ///
name(zambia_events, replace)


gr combine malawi_events zambia_events, iscale(0.6) col(1) graphregion(color(white)) title("")

* Figure 1
graph export "events.pdf"





************ deep backsliding events graphs
*** Malawi
twoway (lpoly tone date if  gov == 0 & country == "Malawi" & parliament == 2009 & date <19150, lcolor("50 50 50") lpattern(shortdash)) (lpoly tone date if  gov ==1 & country == "Malawi" & parliament == 2009 & date <19150, lcolor("50 50 50") lpattern(dash)), xline(18659, lcolor(cranberry)) xline(19054, lcolor(cranberry))  graphregion(color(white)) bgcolor(white) ytitle("Tone") xtitle("Date") legend(fcolor(white) label (2 "Government") label (1 "Opposition")) title("Malawi, parliament of 2009") tlabel(18659 19054, format(%tdnn/DD/YY)  labsize(small) angle(45)) name(malawi_events, replace)

*** Malawi
twoway (lpoly tone date if  gov == 0 & country == "Zambia" & parliament == 2016, lcolor("50 50 50") lpattern(shortdash)) (lpoly tone date if  gov ==1 & country == "Zambia" & parliament == 2016, lcolor("50 50 50") lpattern(dash)), xline(20983, lcolor(cranberry)) xline(21077, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("Tone") xtitle("Date") legend(fcolor(white) label (2 "Government") label (1 "Opposition")) title("Zambia, parliament of 2016") tlabel(20983 21077, format(%tdnn/DD/YY) labsize(small) angle(45)) name(zambia_events, replace)



gr combine malawi_events zambia_events, iscale(0.5) col(1) graphregion(color(white)) title("")

* Figure D5
graph export "deep_events.pdf"







***************************************************************************************************************
***************************************************************************************************************
**** year-level analysis

* construct dataset
use "replication_data_year.dta", clear


eststo clear
eststo: reg tone i.gov i.backsliding minister newcomer indep female parliament year i.e_country, cluster(name)

*** simulations
margins gov
marginsplot, horizontal unique xline(0, lcolor(cranberry))  recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) ytitle("") xtitle("Tone") aspectratio(1) name("predict", replace) title("Effect of being in" "government on Tone") 


eststo: reg av_tone i.gov i.backsliding minister newcomer indep female parliament i.e_country year, cluster(name)

margins gov 
marginsplot, horizontal unique xline(0, lcolor(cranberry)) recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) ytitle("") xtitle("Average Tone") aspectratio(1) name("predict_av", replace) title("Effect of being in" "government on Average Tone") 


gr combine predict predict_av, iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))

*Figure D3
graph export "year_level_h1.pdf", replace


*** Hypotheses 2-3
eststo: reg tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country, cluster(name)


*** simulations
margins gov#backsliding
marginsplot, horizontal unique recast(scatter) xline(0, lcolor(cranberry)) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) name("margins", replace) title("Predictive margins of backsliding" "over government and opposition tone") legend(pos(6))

margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of backsliding on" "government and opposition tone") name("effect1", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of" "government membership on tone") name("effect2", replace) 



eststo: reg av_tone i.gov##i.backsliding minister newcomer indep female parliament year i.e_country i.year, cluster(name)

*** simulations
quietly margins gov#backsliding
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) name("margins_av", replace) title("Predictive margins of backsliding" "over government and opposition av. tone") legend(pos(6))

margins r.backsliding@gov
marginsplot, horizontal unique recast(scatter) yscale(range(-1 2)) xline(0, lcolor(cranberry)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of backsliding on" "government and opposition av. tone") name("effect1_av", replace) 

quietly margins r.gov@backsliding
marginsplot, horizontal unique  recast(scatter) yscale(range(-1 2)) graphregion(color(white)) bgcolor(white) ytitle("") aspectratio(1) title("Marginal effect of" "government membership on av. tone") name("effect2_av", replace) 


gr combine margins effect2 effect1 margins_av effect2_av effect1_av, iscale(0.5) graphregion(color(white)) title("") note("			Note: The 95% confidence intervals are included", size(vsmall))


* Figure D4
graph export "year_level.pdf"

* Table D6
esttab using "year_level.rtf", se bic star(* 0.05 ** 0.01) constant obslast label b(a2)













